import os
import pandas as pd
from tqdm import tqdm

rootdir ='../../xuelangyun_d/Motor_tain/'
dir = os.listdir(rootdir)
f = open(r'test_xiao.csv', 'w')
for i in range(28):
	f.write(str(i)+",")
f.write(str(28)+"\n")

list = os.listdir(os.path.join(rootdir))
names = []
for i in range(len(list)):
	name = list[i].split("_")[0]
	names.append(name)
names =set(names)

def stat_feature_build(sr):
	l = len(sr)
	Min = sr.min()
	Max = sr.max()
	Median = sr.median()
	Mean = sr.mean()
	Std = sr.std()
	Skew = sr.skew()
	Kurt = sr.kurt()
	return Min, Max, Mean, Median, Std, Skew, Kurt

def write(Min, Max, Mean, Median, Std, Skew, Kurt,flag):
	s = str(Min[0]) + "," + str(Min[1]) +","+ str(Max[0]) + "," + str(Max[1]) +","+str(Mean[0]) + "," \
	    + str(Mean[1]) +","+ str(Median[0]) + "," + str(Median[1])+"," +str(Std[0]) + "," + str(Std[1]) +"," +\
	    str(Skew[0]) + "," + str(Skew[1]) +","+	str(Kurt[0]) + "," + str(Kurt[1])
	f.write(s + flag)

for name in tqdm(names):
	s1 = os.path.join(rootdir+"\\", str(name)+"_B.csv")
	s2 = os.path.join(rootdir+"\\", str(name) + "_F.csv")
	data1 = pd.read_csv(open(s1))
	Min, Max, Mean, Median, Std, Skew, Kurt = stat_feature_build(data1)
	f.write(str(name)+",")
	write(Min, Max, Mean, Median, Std, Skew, Kurt,",")

	data2 = pd.read_csv(open(s2))
	Min, Max, Mean, Median, Std, Skew, Kurt = stat_feature_build(data2)
	write(Min, Max, Mean, Median, Std, Skew, Kurt,"\n")
f.close()

